package com.woniuxy.hrp.web.AdminController;

import com.woniuxy.hrp.entity.Hospital;
import com.woniuxy.hrp.entity.PageBean;
import com.woniuxy.hrp.service.HospitalService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @program: hrph
 * @InterfaceName HospitalController
 * @description:医院Controller
 * @author: WY
 **/
import java.util.List;
@Transactional
@CrossOrigin
@RestController
@RequestMapping("/api/v1/admin/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    //查询所有医院信息
    @GetMapping("/list")
    public ResponseEntity list(int page){
        PageBean<Hospital> pageBean = hospitalService.findAll(page);
        return new ResponseEntity("200","OK",pageBean);
    }

    //查询所有医院信息
    @GetMapping("/byname/{page}/{name}")
    public ResponseEntity name(@PathVariable("page") int page,@PathVariable("name") String name){
        PageBean<Hospital> pageBean = hospitalService.findByName(page,name);
        return new ResponseEntity("200","OK",pageBean);
    }

    //增加医院
    @PostMapping("/add")
    public ResponseEntity<String> add(@RequestBody Hospital hospital){
        hospitalService.add(hospital);
        return new ResponseEntity<>("200","OK",null);
    }

    //查询医院信息（根据id）
    @GetMapping("/update")
    public ResponseEntity update(int id){
        Hospital hospital = hospitalService.findById(id);
        return new ResponseEntity("200","OK",hospital);
    }

    //修改医院信息
    @PostMapping("/update")
    public ResponseEntity updateByCondition(@RequestBody Hospital hospital){
        hospitalService.updateByCondition(hospital);
        return ResponseEntity.SUCCESS;
    }

    //删除医院
    @PostMapping("/delete")
    public ResponseEntity delete(int id){
        hospitalService.delete(id);
        return new ResponseEntity("200","OK",null);
    }
}
